package com.mytaobao.main.firsttab;


import com.baseproject.RxSubscriber;
import com.baseproject.datasource.get.procedure.DataProcedure;
import com.baseproject.mvp.MvpBasePresenter;
import com.mytaobao.main.firsttab.func.guessyoulike.ItemGuessYouLike;
import com.mytaobao.requestlayer.AppRequest;

import org.json.JSONArray;

import java.util.List;

import static com.mytaobao.AppConfig.ConstUrl.KEY_ACTION;

//import static com.google.common.base.Preconditions.checkNotNull;

/**
 * 将Presenter分离为基础方法和业务方法
 */
public class FirstTabPresenter extends MvpBasePresenter<FirstTabFragment> implements FirstTabContract.IFirstTabPresenter {


    public FirstTabPresenter() {
    }

    @Override
    public void start() {
//        loadGuessYouLikeList();
//        //获取超实惠imageUrls列表
//        getChaoShiHui(KET_SAVE_PATH_CHAOSHIHUI, "flag = 1", Const.TYPE_CHAO_SHI_HUI);
//        //获取天猫必逛imageUrls列表
//        getChaoShiHui(KET_SAVE_PATH_TIANMAOBIGUANG, "flag = 2", Const.TYPE_TIAN_MAO_BI_GUANG);

        loadPageJSONArray();
    }

    private void loadPageJSONArray() {
        subscriptions.add(AppRequest.getFirstTab(DataProcedure.createCommonRemote(JSONArray.class).setQueryParams(getSimpleQueryParams(KEY_ACTION, "getFirstTabList")))
                .subscribe(new RxSubscriber<List<JSONArray>>(getView()) {
                    @Override
                    public void _onNext(List<JSONArray> jsonArray) {
                        getView().mTangramHelper.getEngine().setData(jsonArray.get(0));
                    }
                }));

    }

    @Override
    public void loadGuessYouLikeList() {
        subscriptions.add(AppRequest.getGuessYouLikeList(DataProcedure.createCommon(ItemGuessYouLike.class)
                .setQueryParams(getSimpleQueryParams(KEY_ACTION, "getItemGuessYouLikeList")))
                .subscribe(new RxSubscriber<List<ItemGuessYouLike>>(getView()) {
                    @Override
                    public void _onNext(List<ItemGuessYouLike> itemGuessYouLikes) {
                        getView().showLikeItems(itemGuessYouLikes);
                    }
                }));
    }
}
